/*!
 * \file nuApplication.cpp
 * \brief Nude's application.
 * \author Nus
 * \date 2008/02/16, 22:18
 */
#include "nuApplication.h"
#include "nuAllocator.h"

BEGIN_RTTI_IMPL_NO_INST(nuApplication);
  RTTI_IMPL(nuApplication, nuObject);
END_RTTI_IMPL_NO_INST(nuApplication);

// Default constructor.
nuApplication::nuApplication()
    : mState(ST_UNINITIALIZE)
{
  // Initialize allocator.
  nuAllocator::initialize();
}

// Default destructor.
nuApplication::~nuApplication()
{
  // Terminate allocator.
  nuAllocator::terminate();
}

// Initialize application.
s32 nuApplication::initApp(void)
{
  if(mState != ST_READY) {
    s32 ret = initProc();
    if(ret == EC_NONE)
      mState = ST_READY;
    return ret;
  }
  return EC_INIT_ERROR;
}

// Run application.
s32 nuApplication::runApp(void)
{
  if(mState != ST_READY)
    return EC_CRITICAL_ERROR;
  return mainProc();
}

// Terminate application.
s32 nuApplication::termApp(void)
{
  if(mState == ST_READY) {
    s32 ret = termProc();
    if(ret == EC_NONE)
      mState = ST_TERMINATED;
    return ret;
  }
  return EC_TERM_ERROR;
}

// Initializing procedure.
s32 nuApplication::initProc(void)
{
  return EC_NONE;
}

// Main procedure.
s32 nuApplication::mainProc(void)
{
  return EC_NONE;
}

// Terminating procedure.
s32 nuApplication::termProc(void)
{
  return EC_NONE;
}
